const http = require("http");
const url = require("url");
const fs = require("fs");
const  server =http.createServer((req,res)=>{
 console.log(req.url)
  let query= url.parse(req.url,true).query;
  console.log(query)

  if(typeof query.username !== 'undefined'){
    try {
        fs.writeFileSync("./data.json",JSON.stringify(query))
        // fs.writeFileSync("./data.json",query)//这样会写入失败
        res.write("success")
        
    } catch (error) {
        console.log(err)
        res.write(err)
        
    }
  }

    res.end()
})

server.listen(8989)